package com.feng.cloud.common.configure;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.feng.cloud.common.jackson.JavaTimeModule;
import com.feng.cloud.common.utils.DateUtils;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.ZoneId;
import java.util.Locale;
import java.util.TimeZone;

/**
 * @ClassName JacksonConfigure
 * @Description TODO
 * @Author Better Feng
 * @Date 2020/1/9 17:34
 * @Version 1.0
 **/
@Configuration
@ConditionalOnClass(ObjectMapper.class)
@AutoConfigureBefore(JacksonAutoConfiguration.class)
public class JacksonConfigure {
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer customizer() {
        return builder -> {
            builder.locale(Locale.CHINA);
            builder.timeZone(TimeZone.getTimeZone(ZoneId.systemDefault()));
            builder.simpleDateFormat(DateUtils.FULL_TIME_SPLIT_PATTERN);
            builder.modules(new JavaTimeModule());
        };
    }
}
